//
// Created by work on 24-6-5.
//

#ifndef IOT_PLAT_CMODELINFO_H
#define IOT_PLAT_CMODELINFO_H

#include <iot_model_device/CRtModelYxInfo.h>
#include <iot_model_device/CRtModelYcInfo.h>
#include <iot_model_device/CRtModelYkInfo.h>
#include <iot_model_device/CRtModelParameterInfo.h>
#include <os/miscellany/CValue.h>

namespace iotplat {
    class CModelInfo {
    public:
        enum EModelCol {
            EName = 0x00,
            EUser,
            EDescr,
            ESn,
            EGroupIngs,
            ELocation,
            ECreate_time,
            EUpdate_time,
            EProducer,
            EValid,
            EConfigs
        };

        std::string name;
        std::string user;
        std::string descr;
        int sn;
        std::string grouping;
        std::string location;
        CDateTime create_time;
        CDateTime update_time;
        std::string producer;
        bool valid;
        Json::Value configs;

        Json::Value toJson();
        void fromJson(Json::Value json);

        static std::map<CModelInfo::EModelCol, std::string> rtModelColToStringMap;
        static std::map<CModelInfo::EModelCol, CValue::EValueType> rtModelDataTypeByField;

    public:
        CValue getValueByField(CModelInfo::EModelCol field);
        explicit  CModelInfo();

    protected:
    };
    static const std::string t_model_name = "t_iot_model";

#define MODEL_ENUM_NAME             CModelInfo::EModelCol::EName
#define MODEL_ENUM_USER             CModelInfo::EModelCol::EUser
#define MODEL_ENUM_DESCR            CModelInfo::EModelCol::EDescr
#define MODEL_ENUM_SN               CModelInfo::EModelCol::ESn
#define MODEL_ENUM_GROUPINGS        CModelInfo::EModelCol::EGroupIngs
#define MODEL_ENUM_LOCATION         CModelInfo::EModelCol::ELocation
#define MODEL_ENUM_CREATE_TIME      CModelInfo::EModelCol::ECreate_time
#define MODEL_ENUM_UPDATE_TIME      CModelInfo::EModelCol::EUpdate_time
#define MODEL_ENUM_PRODUCER         CModelInfo::EModelCol::EProducer
#define MODEL_ENUM_VALID            CModelInfo::EModelCol::EValid
#define MODEL_ENUM_CONFIGS          CModelInfo::EModelCol::EConfigs
#define MODEL_ENUM                  CModelInfo::EModelCol

#define mdoelFieldName(type) CModelInfo::rtModelColToStringMap.find(type)->second
#define mdoelFieldType(type) CModelInfo::rtModelDataTypeByField.find(type)->second

} // iotplat
#endif